$(document).ready(function () {
    query();

});


/*查询全部公告*/
var query = function () {
    $('#dataTable').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.list",
        "sAjaxSource": "http://localhost:8080/punish/queryMyPunish?stuNum=20151000",
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumns": [
            {"mDataProp": "punishId"},
            {"mDataProp": "stuInfoId"},
            {"mDataProp": "stuNum"},
            {"mDataProp": "stuName"},
            {"mDataProp": "stuSex",
                "mRender": function(data) {
                    var value = "男";
                    if (data==1){
                        value = "女";
                    }
                    return value;
                }
            },
            {"mDataProp": "academyName"},
            {"mDataProp": "punishTime"},
            {"mDataProp": "punishType"},
            {"mDataProp": "status",
                "mRender": function(data) {
                    var value = "";
                    if (data==0){
                         value = "<span  class='label label-danger mr10 mb10'>已拒绝</span>";
                    }
                    if (data==1){
                         value = "<span  class='label label-success mr10 mb10'>处分已撤销</span>";
                    }
                    if (data==2){
                         value = "<span  class='label label-primary mr10 mb10'>受理中</span>";
                    }
                    if (data==3){
                        value = "<a href='#'><span  class='label label-yellow mr10 mb10' id='apply'>申请撤销</span></a>";
                    }
                    return value;
                }
            }
        ],
    })
};




$(document).on('click', '#apply', function () {
    //获取punishId
    var punishId = $(this).parents("tr").children(0).eq(0).text();
    $.ajax({
        url: "http://localhost:8080/punish/updatePunishStatus",
        type: "GET",
        async: true,
        data: "punishId=" + punishId+"&status="+2,
        dataType: "json",
        success: function () {
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            layer.msg('操作成功！')
            setTimeout(function () {
                parent.location.reload()
            },1500);
        },
        error: function () {
            layer.alert("操作失败!");
        }
    });


});

